package org.jeecg.modules.demo.expert.web_controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.query.QueryRuleEnum;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.demo.domain.types.entity.CmsDomainType;
import org.jeecg.modules.demo.domain.types.service.ICmsDomainTypeService;
import org.jeecg.modules.demo.expert.info.entity.JkExpert;
import org.jeecg.modules.demo.expert.info.entity.JkExpertAcademic;
import org.jeecg.modules.demo.expert.info.entity.JkExpertProfile;
import org.jeecg.modules.demo.expert.info.entity.JkExpertWork;
import org.jeecg.modules.demo.expert.info.service.IJkExpertAcademicService;
import org.jeecg.modules.demo.expert.info.service.IJkExpertProfileService;
import org.jeecg.modules.demo.expert.info.service.IJkExpertService;
import org.jeecg.modules.demo.expert.info.service.IJkExpertWorkService;
import org.jeecg.modules.demo.expert.info.vo.JkExpertPage;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;


/**
* @Description: 专家信息表
* @Author: jeecg-boot
* @Date:   2025-06-07
* @Version: V1.0
*/
@Tag(name="专家信息表")
@RestController
@RequestMapping("/api/expert")
@Slf4j
public class WebJkExpertController {
   @Autowired
   private IJkExpertService jkExpertService;
   @Autowired
   private IJkExpertWorkService jkExpertWorkService;
   @Autowired
   private IJkExpertAcademicService jkExpertAcademicService;
   @Autowired
   private IJkExpertProfileService jkExpertProfileService;

   @Autowired
   private ICmsDomainTypeService cmsDomainTypeService;



    //通过分类表查询 树状结构
    /**
     * 获取cms_domain_type下的专家
     *
     * @param jkExpert
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "专家信息表-分页列表查询")
    @Operation(summary="专家信息表-分页列表查询")
    @GetMapping(value = "/get_expert_top5_list")
    public Result<List> get_expert_top5_list(JkExpert jkExpert,
                                                 @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                 @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                 HttpServletRequest req) {
        //cms_domain_type 通过根目录获取专家列表
        CmsDomainType cmsDomainTypeParams = new CmsDomainType();
        cmsDomainTypeParams.setPid("0");
        // 自定义查询规则
        Map<String, QueryRuleEnum> customeRuleMap = new HashMap<>();
        // 自定义多选的查询规则为：LIKE_WITH_OR
//        customeRuleMap.put("isVerified", QueryRuleEnum.LIKE_WITH_OR);
//        QueryGenerator.initQueryWrapper(cmsDomainTypeParams, req.getParameterMap(),customeRuleMap);
//        QueryWrapper<CmsDomainType> queryWrapper = QueryGenerator.initQueryWrapper(cmsDomainTypeParams, req.getParameterMap(),customeRuleMap);
        QueryWrapper<CmsDomainType> queryWrapper = QueryGenerator.initQueryWrapper(cmsDomainTypeParams, req.getParameterMap());
        List<CmsDomainType> cmsDomainTypeList = cmsDomainTypeService.list(queryWrapper);
        List<Map> resultList = new ArrayList<>();
        //遍历一级类型
        for(CmsDomainType cmsDomainType : cmsDomainTypeList){
            Map<String,Object> domainType = new HashMap<>();
            domainType.put("id",cmsDomainType.getId());
            domainType.put("title",cmsDomainType.getTypeName());
            cmsDomainTypeParams.setPid(cmsDomainType.getId());
            QueryWrapper<CmsDomainType> queryWrapper1 = QueryGenerator.initQueryWrapper(cmsDomainTypeParams, req.getParameterMap());
            List<CmsDomainType> cmsDomainTypeList1 = cmsDomainTypeService.list(queryWrapper1);
            List<Map> menuItemsList = new ArrayList<>();
            for(CmsDomainType cmsDomainType1 : cmsDomainTypeList1){
                Map<String,Object> domainType1 = new HashMap<>();
                domainType1.put("id",cmsDomainType1.getId());
                domainType1.put("name",cmsDomainType1.getTypeName());
                menuItemsList.add(domainType1);
            }
            domainType.put("menuItems",menuItemsList);
            //获取专家列表
            List<Map> peoperlist = new ArrayList<>();
            List<Map<String,String>> expertList = jkExpertService.query_expert_by_domaincode_top5(cmsDomainType.getTypeCode());
            int expert_count = jkExpertService.query_expert_by_domaincode_count(cmsDomainType.getTypeCode());
            domainType.put("count",expert_count);
            for(Map expert : expertList){
                Map<String,Object> expert1 = new HashMap<>();
                expert1.put("id",expert.get("id"));
                expert1.put("name",expert.get("real_name"));
                expert1.put("zhicheng",expert.get("title"));
                expert1.put("xuewei",expert.get("xueli"));
                expert1.put("zhuanye",expert.get("major"));
                expert1.put("schools",expert.get("graduation_school"));
                expert1.put("danwei",expert.get("organization"));
                expert1.put("expertises",expert.get("expertise_field"));
                expert1.put("expertises_name",expert.get("domain_name"));
                expert1.put("persone_phone",expert.get("persone_phone"));
                peoperlist.add(expert1);
            }

            domainType.put("peoperlist",peoperlist);
            resultList.add(domainType);
        }


//        // 自定义查询规则
//        Map<String, QueryRuleEnum> customeRuleMap = new HashMap<>();
//        // 自定义多选的查询规则为：LIKE_WITH_OR
//        customeRuleMap.put("isVerified", QueryRuleEnum.LIKE_WITH_OR);
//        QueryWrapper<JkExpert> queryWrapper = QueryGenerator.initQueryWrapper(jkExpert, req.getParameterMap(),customeRuleMap);
//        Page<JkExpert> page = new Page<JkExpert>(pageNo, pageSize);
//        IPage<JkExpert> pageList = jkExpertService.page(page, queryWrapper);
        return Result.OK(resultList);
    }



}
